package ace.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.catalina.servlets.WebdavServlet;

import com.alibaba.fastjson.JSONArray;

import ace.model.Menu;
import web.annotation.Method;
import web.annotation.Param;
import web.annotation.Type;
import web.jdbc.QuerySQL;
import web.servlet.WebServlet;

@Type("menuController")
public class MenuController {

	QuerySQL<Menu> qs = new QuerySQL<>();
	
	List<Menu> listMenu = new ArrayList<>();
	
	public List<Menu> getListMenu() {
		return listMenu;
	}
	public void setListMenu(List<Menu> listMenu) {
		this.listMenu = listMenu;
	}


	@Method("showMenu")
	public String showMenu(){
		listMenu = qs.executeSQL("select * from base_menu").getResultList(Menu.class);
		String js = JSONArray.toJSONString(listMenu);
		return js;

	}
	
	@Method(value="getMenuUrl",isReturnPage = true)
	public String getMenuUrl(@Param("id")String id){
		Object[] obj =  qs.executeSQL("select url from base_menu where id = "+id).getSingleResult();
		if(obj == null)
			return "";
		return obj[0].toString();
	}
}
